/*
 * 改程序封装了GlobalProvinces_extend.js、GlobalProvinces_main.js两个文件中的对象和数组
 * 
 * @作者：曹鑫
 * @创建日期：2016-04-05
 * 
 */


function initLocation(option)
{
	option = jQuery.extend({
		sheng:"sheng",		//省的网页ID
		shi:"shi",			//市的网页ID
		xian:"xian",		//县的网页ID
		xiang:"xiang",		//乡的网页ID
		sheng_val:"",		//默认省份
		shi_val:"",			//默认地区
		xian_val:"",		//默认县
		xiang_val:""		//默认乡镇
	},option||{});
	
	if(option.sheng_val == ""){
		option.sheng_val == "-1";
	}
		
	var gpm = new GlobalProvincesModule;
	gpm.def_province = ["-- 全国 --", -1];
	gpm.initProvince(document.getElementById(option.sheng));
	gpm.initCity(document.getElementById(option.shi), option.sheng_val);
	gpm.initCounty(document.getElementById(option.xian), option.sheng_val, option.shi_val);
	gpm.initTown(document.getElementById(option.xiang), option.sheng_val, option.shi_val, option.xian_val);

	gpm.selectProvincesItem(document.getElementById(option.sheng), option.sheng_val);
	gpm.selectCountyItem(document.getElementById(option.xian), option.xian_val);
	gpm.selectCityItem(document.getElementById(option.shi), option.shi_val);

	if(document.getElementById(option.xiang).options.length > 1){
		gpm.selectCountyItem(document.getElementById(option.xiang), option.xiang_val);
		document.getElementById(option.xiang).style.display ="inline";
		document.getElementById(option.xiang).style.display = "inline";
	}

	var onchgProv = function()
	{	
		gpm.initCity(document.getElementById(option.shi), gpm.getSelValue(document.getElementById(option.sheng)));
		gpm.initCounty(document.getElementById(option.xian), '', '');		/* clear city2 select options*/
		gpm.initTown(document.getElementById(option.xiang), '', '', '');
	}
	var onchgCity = function()
	{
		gpm.initCounty(document.getElementById(option.xian), gpm.getSelValue(document.getElementById(option.sheng)), gpm.getSelValue(document.getElementById(option.shi)));
		gpm.initTown(document.getElementById(option.xiang), '', '', '');
	}

	var onchgStreet = function(){
		gpm.initTown(document.getElementById(option.xiang), gpm.getSelValue(document.getElementById(option.sheng)), gpm.getSelValue(document.getElementById(option.shi)), gpm.getSelValue(document.getElementById(option.xian)));
	}

	$("#" + option.sheng).change(onchgProv);
	$("#" + option.shi).change(onchgCity);
	$("#" + option.xian).change(onchgStreet);
}